<html>
<div id="myheader">
<?php
error_reporting(E_ALL);
?>
</div>


<title>OSPMS</title>
<head>


</head>


<div id="mybody">


<?php


echo "<table style='border: solid 1px black;'>";

$servername = "localhost";
$username = "ospms";
$password = "ospms";
$dbname = "OSPMS";


class TableRows extends RecursiveIteratorIterator {
	function __construct($it) {
        parent::__construct($it, self::LEAVES_ONLY);
    }

    function current() {
//        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
        return "<td style='width:150px;border:1px solid black;'>" . parent::current(). "</td>";
    }

    function beginChildren() {
        echo "<tr>";
    }

    function endChildren() {
        echo "</tr>" . "\n";
    }
}


try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);


$select = $conn->query('SELECT * FROM user_programs');

$total_column = $select->columnCount();
//var_dump($total_column);

for ($counter = 0; $counter <= $total_column; $counter ++) {
    $meta = $select->getColumnMeta($counter);
    $column[] = $meta['name'];
}
//print_r($column);

    $stmt = $conn->prepare("SELECT program_id, project_id, program_name, program_location FROM user_programs");
    $stmt->execute();
    $result2 = $stmt->setFetchMode(PDO::FETCH_ASSOC);
    $result2 = $stmt->fetchAll();
//    var_dump($result2);
    $my_count = count($result2);
    echo ' ';
//    print '\n';
//    print_r($my_count);

//    for( $i=0; $i<count($result2); $i++ )
    for( $i=0; $i<1; $i++ )
    {
    	$my_file_id = $result2[$i]['file_id'];
    	$my_folder_id = $result2[$i]['folder_id'];
    	$my_filename = $result2[$i]['file_name'];
    	$my_location = $result2[$i]['file_location'];

#	echo "<tr>". " \n";
#        echo "<td style='width:150px;border:1px solid black;'>"; 
#    	print($my_file_id);
#	echo "</td>";
#        echo "<td style='width:150px;border:1px solid black;'>"; 
#    	print($my_folder_id);
#	echo "</td>";
#        echo "<td style='width:150px;border:1px solid black;'>"; 
#    	print($my_filename);
#	echo "</td>";
#        echo "<td style='width:150px;border:1px solid black;'>"; 
#	echo '<a href="https://test2.transpolink.com/uploads/';
#    	print(substr($my_location,16));
#    	print($my_filename);
#	echo '">';
#    	print($my_filename);
#	echo '</a>';
#	echo "</td>";
#        echo "</tr>" . "\n";

//    $oct = new Octave("test1","/var/www/uploads/SAVED");
//    $command = "sim1.m";
//    $out=$oct->NewQuery($command);
//    $out=$oct->GetOutput($command);

    $user_dir = "/var/www/uploads/SAVED";

//    file_put_contents($user_dir."/".OCTAVE_IN, $query);
   
    $maxtime = CF_MAXTIME;
    $maxsize = CF_MAXSIZE;

    set_time_limit($maxtime);

    passthru("cd ".$user_dir. "; octave sim1.m ");

//    passthru("cd ".$user_dir.";ulimit -f ".$maxsize." -m 10000 -t ".$maxtime."; octave sim1.m ");
//    $output = file_get_contents($user_dir."/".OCTAVE_OUT);

//    echo '<iframe src="https://test2.transpolink.com/uploads/SAVED/00000.png" style=\"width: 90%; width: 1200 px; height: 900px\" scrolling=\"yes\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"1\" vspace=\"0\" hspace=\"0\"> </iframe>';
    echo '<ol><li><iframe src="https://test2.transpolink.com/uploads/SAVED/00000.png" style=\"width: 90%; width: 120 px; height: 90px\" scrolling=\"yes\" marginwidth=\"0\" marginheight=\"0\" frameborder=\"1\" vspace=\"0\" hspace=\"0\"> </iframe> </li></ol>';

    }


//    $dsn = null;
    }
catch(PDOException $e)
    {
    echo "Error: " . $e->getMessage();
    }
$conn = null;
echo "</table>";
?> 

</div>
</div>


